﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ConnectionBuilder
{
    public partial class ConnectionOracle : UserControl
    {
        #region "Delegate"
        /// <summary>
        /// botão conectar
        /// </summary>
        public delegate void ConnectDelegate(Object sender, EventArgs e);
        /// <summary>
        /// evento: clicar em Connect
        /// </summary>
        public event ConnectDelegate OnConnect;

        /// <summary>
        /// botão cancelar
        /// </summary>
        public delegate void CancelDelegate(Object sender, EventArgs e);
        /// <summary>
        /// evento: clicar em Connect
        /// </summary>
        public event CancelDelegate OnCancel;

        /// <summary>
        /// botão help
        /// </summary>
        public delegate void HelpDelegate();
        /// <summary>
        /// evento: clicar em help
        /// </summary>
        public event HelpDelegate OnHelp;

        /// <summary>
        /// botão help
        /// </summary>
        public delegate void OptionsDelegate();
        /// <summary>
        /// evento: clicar em options
        /// </summary>
        public event OptionsDelegate OnOption;

        /// <summary>
        /// delegações de erros
        /// </summary>
        public delegate void ErrorDelegate(Exception e);
        /// <summary>
        /// erros no componente
        /// </summary>
        public event ErrorDelegate OnError;
        #endregion

        public ConnectionOracle()
        {
            InitializeComponent();
        }

        #region "delegates para os botões"
        /// <summary>
        /// botão connet
        /// </summary>
        private void cmdConnect_Click(Object sender, EventArgs e)
        {
            if (OnConnect != null)
                OnConnect(sender, e);
        }

        /// <summary>
        /// botão cancel
        /// </summary>
        private void cmdCancel_Click(object sender, EventArgs e)
        {
            if (OnCancel != null)
                OnCancel(sender, e);
        }

        /// <summary>
        /// botão help
        /// </summary>
        private void cmdHelp_Click(object sender, EventArgs e)
        {
            if (OnHelp != null)
                OnHelp();
        }

        /// <summary>
        /// botão options
        /// </summary>
        private void cmdOptions_Click(object sender, EventArgs e)
        {
            if (OnOption != null)
                OnOption();
        }
        #endregion

        #region "Gets do componente"
        /// <summary>
        /// get server name
        /// </summary>
        /// <returns>String</returns>
        public String GetServerName()
        {
            return cboServerName.Text;
        }
        /// <summary>
        /// get user name
        /// </summary>
        /// <returns>String</returns>
        public String GetUserName()
        {
            return txtUser.Text;
        }
        /// <summary>
        /// get password
        /// </summary>
        /// <returns>String</returns>
        public String GetPassword()
        {
            try
            {
                return password.Encrypt(txtPassword.Text, "ORACLEBuilder");
            }
            catch (Exception ex)
            {
                if (OnError != null)
                    OnError(ex);
                throw;
            }
        }
        /// <summary>
        /// get remember connection
        /// </summary>
        /// <returns>Boolean</returns>
        public Boolean GetRememberIt()
        {
            return chkRemember.Checked;
        }
        #endregion
    }
}
